# 8 在2个文件中存放了英文计算机技术文章(可以选择2篇关于Python技术文件操作处理技巧的2篇英文技术文章), 请读取文章内容,进行词频的统计;并分别输出统计结果到另外的文件存放;
#     比较这2篇文章的相似度(如果词频最高的前10个词,重复了5个,相似度就是50%;重复了6个,相似度就是60% ,......);

with open("a.txt") as f:
    lines = f.read()
dict = {}
for line in lines:
    if line in dict:
        dict[line] += 1
    else:
        dict[line] = 1
ldict = list(dict.items())
ldict.sort(key=lambda x:x[1],reverse = True)
count = 0
for i in ldict:
    print(i,"\t",end="")
    count+=1
print(" ")
with open("b.txt") as f:
    lines = f.read()
dict1 = {}
for line in lines:
    if line in dict1:
        dict1[line] += 1
    else:
        dict1[line] = 1
ldict1 = list(dict1.items())
ldict1.sort(key=lambda x:x[1],reverse = True)
count = 0
for i in ldict1:
    print(i,"\t",end="")
    count+=1
print(" ")
l = -1
for i in range(0,10) :
    if ldict[i][0] == ldict1[i][0]:
        l += 1
    else:
        continue
print("相似度为百分之{}0".format(l))